package org.hackystat.linkedservicedata.ui.projects;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.hackystat.linkedservicedata.client.LinkedServiceDataClientException;
import org.hackystat.linkedservicedata.resource.linkedservicedata.LinkedServiceDataResource;
import org.hackystat.linkedservicedata.ui.LinkedServiceDataUI;
import org.hackystat.linkedservicedata.vocabularies.DoapVocab;
import org.hackystat.linkedservicedata.vocabularies.HackystatConstants;
import org.hackystat.linkedservicedata.vocabularies.HackystatVocab;
import org.hackystat.sensorbase.resource.projects.jaxb.Project;
import org.hackystat.utilities.tstamp.Tstamp;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.vocabulary.DC;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;

/**
 * Panel to list and edit all the available projects.
 *
 * @author Myriam Leggieri.
 *
 */
public class ProjectsPanel extends JPanel implements KeyListener, ActionListener, ItemListener {

  /**
   * Prefix to identify that one of the 'edit' button has been pressed
   */
  private static final String EDITPREFIX = "EDIT" + HackystatConstants.SEPARATOR1_ID;

  /**
   * Prefix to identify that one of the 'triplify' button has been pressed
   */
  private static final String TRIPLIFYPREFIX = "TRIPLIFY" + HackystatConstants.SEPARATOR1_ID;

  /**
   * Prefix to identify that one of the 'save' button has been pressed
   */
  private static final String SAVEPREFIX = "SAVE" + HackystatConstants.SEPARATOR1_ID;

  /**
   * Prefix to identify that one of the 'ok' button has been pressed
   */
  private static final String OKPREFIX = "OK" + HackystatConstants.SEPARATOR1_ID;

  /** RDF model containing a list of stored projects. */
  private Model projectsListModel = null;

  /**
   * List of project profile's data. Each profile is associated with text fields containing its data
   * which will become editable if one requires to edit them.
   */
  private LinkedList<ProjectProfileUIComponent> profilesList = null;

  /** Parent frame. */
  private LinkedServiceDataUI mainframe = null;

  /** Dialog used for displaying the 'please wait' window. */
  private JDialog dialog = null;

  /** Clear cache button. */
  private JButton clearCacheButton = null;

  /**
   * Edit button. Each edit button will be associated with an action command starting with 'edit_'
   * and ending with the correspondent user profile's email
   */
  private JButton editButton = null;

  /** Triplify all button. */
  private JButton triplifyAllButton = null;

  /** Triplify one profile button. */
  private JButton triplifyOneButton = null;

  /** Action label. */
  private JLabel actionLabel = null;

  /** Owner's email label. */
  private JLabel ownerLabel = null;

  /** Description label. */
  private JLabel descriptionLabel = null;

  /** Tags label. */
  private JLabel toolsLabel = null;

  /** Tags value label. */
  private JLabel toolsValueLabel = null;

  /** Tags text. */
  private JTextField toolsValueText = null;

  /** Add tags button. */
  private JButton addToolsButton = null;

  /** Remove tags button. */
  private JButton removeToolsButton = null;

  /** Dev phase label. */
  private JLabel devPhaseLabel = null;

  /** Tags value label. */
  private JLabel devPhaseValueLabel = null;

  /** Tags text. */
  private JTextField devPhaseValueText = null;

  /** Add tags button. */
  private JButton addDevPhaseButton = null;

  /** Remove tags button. */
  private JButton removeDevPhaseButton = null;

  /** Tags label. */
  private JLabel tagsLabel = null;

  /** Tags value label. */
  private JLabel tagsValueLabel = null;

  /** Tags text. */
  private JTextField tagsValueText = null;

  /** Add tags button. */
  private JButton addTagsButton = null;

  /** Remove tags button. */
  private JButton removeTagsButton = null;

  /** Start date label. */
  private JLabel startDateLabel = null;

  /** End date label. */
  private JLabel endDateLabel = null;

  /** Last modification date label. */
  private JLabel modifiedDateLabel = null;

  /** Wikis label. */
  private JLabel wikisLabel = null;

  /** SeeAlso label. */
  private JLabel seeAlsoLabel = null;

  /** SameAs label. */
  private JLabel sameAsLabel = null;

  /** Roles combo label. */
  private JLabel rolesComboLabel = null;

  /** Roles combo. */
  private JComboBox rolesCombo = null;

  /** Members/Role list label. */
  private JLabel membersRoleListLabel = null;

  /** Member value label. */
  private JLabel membersRoleValueLabel = null;

  /** Member value text. */
  private JTextField membersRoleValueText = null;

  /** Add duplicates button. */
  private JButton addMembersRoleButton = null;

  /** Remove sameAs button. */
  private JButton removeMembersRoleButton = null;

  /** Mirrors label. */
  private JLabel mirrorsLabel = null;

  /** Programming Languages label. */
  private JLabel progrLangsLabel = null;

  /** Operating System label. */
  private JLabel osLabel = null;

  /** Operating Systems text. */
  private JTextArea osText = null;

  /** Bug DB label. */
  private JLabel bugDbLabel = null;

  /** Bug DB text. */
  private JTextArea bugDbText = null;

  /** Repository label. */
  private JLabel repLabel = null;

  /** Repository text. */
  private JTextField repText = null;

  /** Anonymous repository label. */
  private JLabel repAnonLabel = null;

  /** Anonymous repository text. */
  private JTextField repAnonText = null;

  /** Repository Web browser interface label. */
  private JLabel repWebInterfaceLabel = null;

  /** Repository Web browser interface text. */
  private JTextField repWebInterfaceText = null;

  /** Project Name label. */
  private JLabel projNameLabel = null;

  /** Visibility label. */
  private JLabel visibilityLabel = null;

  /** Visibility text. */
  private JTextField visibilityText = null;

  /** Email text. */
  private JTextField ownerText = null;

  /** Nickname text. */
  private JTextArea descriptionText = null;

  /** Homepage text. */
  private JTextArea wikisText = null;

  /** Weblog text. */
  private JTextArea progrLangsText = null;

  /** ID text. */
  private JTextField projNameText = null;

  /** Milestone text. */
  private JTextArea mirrorsText = null;

  /** Creation date text. */
  private JTextField startDateText = null;

  /** Closure date text. */
  private JTextField endDateText = null;

  /** Modified date text. */
  private JTextField modifiedDateText = null;

  /** Password text. */
  private JPasswordField passwordText = null;

  /** Skills label. */
  private JLabel skillsLabel = null;

  /** Profile Panels dimension. */
  // private Dimension profilePanelDimension = new Dimension(800, 200);
  /** Search button. */
  private JButton okButton = null;

  /** Search button. */
  private JButton searchButton = null;

  /** Refresh button. */
  private JButton refreshButton = null;

  /** Save button. */
  private JButton saveButton = null;

  /** Element that split entries into text areas. */
  private String splitElem = ",";

  /**
   * RDF serialization language used to obtain the currently displayed data.
   */
  private String language = null;

  /**
   * User (identified by its email) whose correspondent panel is currently in an editing mode.
   */
  private ProjectProfileUIComponent profileInEditingMode = null;

  private LinkedList<Model> profilesModelList = null;

  /**
   * Auto-generated serial version ID
   */
  private static final long serialVersionUID = 2927369587956956550L;

  public ProjectsPanel(LinkedServiceDataUI mainframe) {
    this.mainframe = mainframe;
  }

  private void refreshProfiles() {
    profilesList = new LinkedList<ProjectProfileUIComponent>();
    profilesModelList = new LinkedList<Model>();
    if (profileInEditingMode != null) {
      disableAllJTextFields(profileInEditingMode);
      disableAllJTextAreas(profileInEditingMode);
    }
    profileInEditingMode = null;
    displayWaitingDialog();
    this.language = mainframe.getLiSeDClient().getLanguage();
    try {
      projectsListModel = mainframe.getLiSeDClient().getProjectsList();
      if (projectsListModel != null) {
        LinkedServiceDataResource.printModel(projectsListModel);
        NodeIterator nodit = projectsListModel.listObjects();
        RDFNode nod = null;
        Model tmpModel = null;
        String projuri = null;
        while (nodit.hasNext()) {
          nod = nodit.next();
          if (nod.isLiteral()) {
            projuri = ((Literal) nod).getLexicalForm();
          }
          else if (nod.isResource() && !nod.isAnon()) {
            projuri = ((Resource) nod).getURI();
          }
          if (!projuri.equals(RDF.Bag.getURI()) && !projuri.contains("@hackystat.org")
              && !projuri.endsWith(HackystatConstants.DEFAULT_PROJECT)) {
            try {
              tmpModel = mainframe.getLiSeDClient().getUriProjectAsLinkedData(projuri);
            }
            catch (LinkedServiceDataClientException e) {
              JOptionPane.showMessageDialog(this,
                  "Unable to retrieve projects profile for project = " + projuri + ".",
                  "Hackystat - Error Message", JOptionPane.ERROR_MESSAGE);
              tmpModel = null;
            }
            if (tmpModel != null) {
              profilesModelList.add(tmpModel);
            }
          }
        }
        StmtIterator it = null;
        ProjectProfile profile = null;
        ProjectProfileUIComponent projProfUIComponent = null;
        Statement statement = null;
        Property predicate = null;
        String object = null;
        for (Model model : profilesModelList) {
          it = model.listStatements();
          profile = new ProjectProfile();
          projProfUIComponent = new ProjectProfileUIComponent();
          while (it.hasNext()) {
            statement = it.next();
            predicate = statement.getPredicate();
            nod = statement.getObject();
            if (nod.isLiteral()) {
              object = ((Literal) nod).getLexicalForm();
            }
            else if (nod.isResource() && !nod.isAnon()) {
              object = ((Resource) nod).getURI();
            }
            if (predicate.equals(DoapVocab.DESCRIPTION)) {
              profile.description = object;
            }
            else if (predicate.equals(DoapVocab.MAINTAINER)) {
              profile.addMembersRole(object, DoapVocab.MAINTAINER.getLocalName());
            }
            else if (predicate.equals(HackystatVocab.PROJECT_OWNER)) {
              profile.owner = object.substring(object.lastIndexOf("/") + 1, object.length());
            }
            else if (predicate.equals(DoapVocab.NAME)) {
              profile.name = object;
            }
            else if (predicate.equals(DoapVocab.CREATED)) {
              profile.startDate = object;
            }
            else if (predicate.equals(HackystatVocab.ENDED)) {
              profile.endDate = object;
            }
            else if (predicate.equals(HackystatVocab.MODIFIED)) {
              profile.modifiedDate = object;
            }
            else if (predicate.equals(HackystatVocab.MEMBER)) {
              profile.addMembersRole(object, HackystatVocab.MEMBER.getLocalName());
            }
            else if (predicate.equals(HackystatVocab.SPECTATOR)) {
              profile.addMembersRole(object, HackystatVocab.SPECTATOR.getLocalName());
            }
            else if (predicate.equals(HackystatVocab.INVITATED)) {
              profile.addMembersRole(object, HackystatVocab.INVITATED.getLocalName());
            }
            else if (predicate.equals(DoapVocab.CATEGORY)) {
              profile.addTag(object);
            }
            else if (predicate.equals(OWL.sameAs)) {
              profile.addSameAs(object);
            }
            else if (predicate.equals(RDFS.seeAlso)) {
              profile.addSeeAlso(object);
            }
            else if (predicate.equals(HackystatVocab.PRIVACY_LEVEL)) {
              profile.visibility = object;
            }
            else if (predicate.equals(DoapVocab.REPOSITORY)) {
              profile.repository = object;
            }
            else if (predicate.equals(DoapVocab.ANON_ROOT)) {
              profile.repositoryAnonymous = object;
            }
            else if (predicate.equals(DoapVocab.BROWSE)) {
              profile.repositoryWebBrowserInterface = object;
            }
            else if (predicate.equals(HackystatVocab.INCLUDES_PHASE)) {
              profile.addDevelopmentPhase(object);
            }
            else if (predicate.equals(DoapVocab.DOWNLOAD_MIRROR)) {
              profile.addMirrors(object);
            }
            else if (predicate.equals(DoapVocab.WIKI)) {
              profile.addWikis(object);
            }
            else if (predicate.equals(DoapVocab.BUG_DATABASE)) {
              profile.addBugDB(object);
            }
            else if (predicate.equals(DoapVocab.DEVELOPER)) {
              profile.addMembersRole(object, DoapVocab.DEVELOPER.getLocalName());
            }
            else if (predicate.equals(DoapVocab.HELPER)) {
              profile.addMembersRole(object, DoapVocab.HELPER.getLocalName());
            }
            else if (predicate.equals(DoapVocab.DOCUMENTER)) {
              profile.addMembersRole(object, DoapVocab.DOCUMENTER.getLocalName());
            }
            else if (predicate.equals(DoapVocab.TESTER)) {
              profile.addMembersRole(object, DoapVocab.TESTER.getLocalName());
            }
            else if (predicate.equals(DoapVocab.TRANSLATOR)) {
              profile.addMembersRole(object, DoapVocab.TRANSLATOR.getLocalName());
            }
            else if (predicate.equals(DoapVocab.LANGUAGE)) {
              profile.addProgrLangs(object);
            }
            else if (predicate.equals(HackystatVocab.ON_OPERATING_SYSTEM)) {
              profile.addOS(object);
            }
            else if (predicate.equals(HackystatVocab.USES_TOOL)) {
              profile.addTool(object);
            }
            else if (predicate.equals(HackystatVocab.BUILD_QUALITY)) {
              if (nod.isAnon()) {
                object = ((Resource) nod).getProperty(HackystatVocab.AVERAGE_VALUE).getString()
                    + " ; " + ((Resource) nod).getProperty(DC.date).getString();
              }
              profile.setBuildQuality(String.valueOf(object));
            }
            else if (predicate.equals(HackystatVocab.UNIT_TEST_QUALITY)) {
              if (nod.isAnon()) {
                object = ((Resource) nod).getProperty(HackystatVocab.AVERAGE_VALUE).getString()
                    + " ; " + ((Resource) nod).getProperty(DC.date).getString();
              }
              profile.setUnitTestQuality(String.valueOf(object));
            }
            else if (predicate.equals(HackystatVocab.COVERAGE_QUALITY)) {
              if (nod.isAnon()) {
                object = ((Resource) nod).getProperty(HackystatVocab.AVERAGE_VALUE).getString()
                    + " ; " + ((Resource) nod).getProperty(DC.date).getString();
              }
              profile.setCoverageQuality(String.valueOf(object));
            }
            else if (predicate.equals(HackystatVocab.DEVELOPMENT_TIME)) {
              if (nod.isAnon()) {
                object = ((Resource) nod).getProperty(HackystatVocab.AVERAGE_VALUE).getString()
                    + " ; " + ((Resource) nod).getProperty(DC.date).getString();
              }
              profile.setDevelopmentTime(String.valueOf(object));
            }
            else if (predicate.equals(HackystatVocab.COMMIT_FREQUENCY)) {
              if (nod.isAnon()) {
                object = ((Resource) nod).getProperty(HackystatVocab.AVERAGE_VALUE).getString()
                    + " ; " + ((Resource) nod).getProperty(DC.date).getString();
              }
              profile.setCommitFrequency(String.valueOf(object));
            }
            else if (predicate.equals(HackystatVocab.AMOUNT_OF_CODE_ISSUES)) {
              if (nod.isAnon()) {
                object = ((Resource) nod).getProperty(HackystatVocab.AVERAGE_VALUE).getString()
                    + " ; " + ((Resource) nod).getProperty(DC.date).getString();
              }
              profile.setAmountOfIssues(String.valueOf(object));
            }

          }
          projProfUIComponent.profile = profile;
          projProfUIComponent.textFieldsList = makeJTextFields(profile);
          projProfUIComponent.textAreasList = makeJTextAreas(profile);
          projProfUIComponent.tagsJList = createJListFromList(profile.getTags());
          projProfUIComponent.toolsJList = createJListFromList(profile.getTools());
          projProfUIComponent.seeAlsoJList = createJListFromList(profile.getSeeAlso());
          projProfUIComponent.sameAsJList = createJListFromList(profile.getSameAs());
          projProfUIComponent.devPhasesJList = createJListFromList(profile.getDevelopmentPhases());
          projProfUIComponent.membersRoleJList = createJListFromTwoElemList(profile
              .getMembersRole());
          projProfUIComponent.skillsJList = createJListFromMap(profile.getSkills());
          profilesList.add(projProfUIComponent);
        }
      }
    }
    catch (LinkedServiceDataClientException e) {
      JOptionPane.showMessageDialog(this, e.getMessage(), "Hackystat - Error Message",
          JOptionPane.ERROR_MESSAGE);
      e.printStackTrace();
    }
    finally {
      disposeDialog();
    }
  }

  @Override
  public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub

  }

  @Override
  public void keyReleased(KeyEvent e) {
    // TODO Auto-generated method stub

  }

  @Override
  public void keyTyped(KeyEvent e) {
    // TODO Auto-generated method stub

  }

  private void enableJTextFieldsToBeEdited(ProjectProfileUIComponent profile) {
    for (int i = 0; i < profile.textFieldsList.size(); i++) {
      if (i != 1 && i != 2) {
        profile.textFieldsList.get(i).setEditable(true);
      }
    }
  }

  private void enableJTextAreasToBeEdited(ProjectProfileUIComponent profile) {
    for (JTextArea area : profile.textAreasList) {
      area.setEditable(true);
    }
  }

  private void disableAllJTextFields(ProjectProfileUIComponent profile) {
    for (JTextField field : profile.textFieldsList) {
      field.setEditable(false);
    }
  }

  private void disableAllJTextAreas(ProjectProfileUIComponent profile) {
    for (JTextArea field : profile.textAreasList) {
      field.setEditable(false);
    }
  }

  @Override
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    String owner = null, projname = null;
    // System.out.println("ACTION PERFORMED!!");
    // System.out.println("e.getActionCommand()="+e.getActionCommand());
    if (source.equals(clearCacheButton)) {

      try {
        mainframe.clearServerCache();
      }
      catch (LinkedServiceDataClientException e1) {
        JOptionPane.showMessageDialog(this, e1.getMessage(), "Hackystat - Error Message",
            JOptionPane.ERROR_MESSAGE);
        e1.printStackTrace();
      }

    }
    else if (source.equals(triplifyAllButton)) {

      Iterator<Model> it = profilesModelList.iterator();
      Model model = null;
      if (it.hasNext()) {
        model = it.next();
      }
      while (it.hasNext()) {
        model = model.union(it.next());
      }
      String serializedModel = mainframe.getLiSeDClient().serializeRDFModel(model, this.language);
      displayRDFContentDialog(serializedModel);

    }
    else if (e.getActionCommand().startsWith(TRIPLIFYPREFIX)) {

      owner = e.getActionCommand().split(HackystatConstants.SEPARATOR1_ID)[1];
      projname = e.getActionCommand().split(HackystatConstants.SEPARATOR1_ID)[2];
      Iterator<Model> it = profilesModelList.iterator();
      String serializedModel = null;
      Model model = null;
      while (it.hasNext() && serializedModel == null) {
        model = it.next();
        if (model.contains(null, DoapVocab.NAME, projname)
            && model.contains(null, DoapVocab.MAINTAINER, LinkedServiceDataResource
                .getUserUri(owner))) {
          serializedModel = mainframe.getLiSeDClient().serializeRDFModel(model, this.language);
          displayRDFContentDialog(serializedModel);
        }
      }

    }
    else if (e.getActionCommand().startsWith(EDITPREFIX)) {

      if (profileInEditingMode == null) {
        owner = e.getActionCommand().split(HackystatConstants.SEPARATOR1_ID)[1];
        projname = e.getActionCommand().split(HackystatConstants.SEPARATOR1_ID)[2];
        Iterator<ProjectProfileUIComponent> it = profilesList.iterator();
        ProjectProfileUIComponent profileComponent = null, searchedProfile = null;
        while (it.hasNext() && searchedProfile == null) {
          profileComponent = it.next();
          if (profileComponent.profile.name.equals(projname)
              && profileComponent.profile.owner.equals(owner)) {
            searchedProfile = profileComponent;
          }
        }
        profileInEditingMode = searchedProfile;
        enableJTextFieldsToBeEdited(profileInEditingMode);
        enableJTextAreasToBeEdited(profileInEditingMode);
        JOptionPane.showMessageDialog(this, "Enter desired changes into the editable fields.",
            "Hackystat - Message", JOptionPane.PLAIN_MESSAGE);
        refresh();
      }
      else {
        JOptionPane.showMessageDialog(this, "You can't edit more than one project at a time",
            "Hackystat - Error Message", JOptionPane.ERROR_MESSAGE);
        return;
      }

    }
    else if (e.getActionCommand().startsWith(SAVEPREFIX)) {
      owner = e.getActionCommand().split(HackystatConstants.SEPARATOR1_ID)[1];
      projname = e.getActionCommand().split(HackystatConstants.SEPARATOR1_ID)[2];
      Project projObj = null;

      String visibility = null, repAnon = null, repWeb = null, rep = null, start = null, end = null, modified = null;

      projObj = new Project();

      visibility = profileInEditingMode.textFieldsList.get(0).getText();
      start = profileInEditingMode.textFieldsList.get(3).getText();
      modified = profileInEditingMode.textFieldsList.get(4).getText();
      end = profileInEditingMode.textFieldsList.get(5).getText();
      repAnon = profileInEditingMode.textFieldsList.get(6).getText();
      rep = profileInEditingMode.textFieldsList.get(7).getText();
      repWeb = profileInEditingMode.textFieldsList.get(8).getText();

      String wikis = getNewElems(profileInEditingMode.textAreasList.get(0).getText(),
          profileInEditingMode.profile.getWikis(), splitElem), progrlangs = getNewElems(
          profileInEditingMode.textAreasList.get(1).getText(), profileInEditingMode.profile
              .getProgrLangs(), splitElem), mirrors = getNewElems(
          profileInEditingMode.textAreasList.get(2).getText(), profileInEditingMode.profile
              .getMirrors(), splitElem), bugdbs = getNewElems(profileInEditingMode.textAreasList
          .get(3).getText(), profileInEditingMode.profile.getBugDBs(), splitElem), osystems = getNewElems(
          profileInEditingMode.textAreasList.get(4).getText(), profileInEditingMode.profile
              .getOperatingSystems(), splitElem), description = profileInEditingMode.textAreasList
          .get(5).getText(), tags = getNewElems(profileInEditingMode.tagsJList,
          profileInEditingMode.profile.getTags()), tools = getNewElems(
          profileInEditingMode.tagsJList, profileInEditingMode.profile.getTags()), devPhases = getNewElems(
          profileInEditingMode.devPhasesJList, profileInEditingMode.profile.getDevelopmentPhases());
      /**
       * Only those properties which have been actually modified are posted to increase performance.
       */
      if (!visibility.equals(profileInEditingMode.profile.visibility)) {
        projObj.addProperty(HackystatConstants.PROFILE_VISIBILITY, visibility);
      }
      if (start != null && !start.equals(profileInEditingMode.profile.startDate)
          && start.trim() != "") {
        try {
          projObj.setStartTime(Tstamp.makeTimestamp(start));
        }
        catch (Exception e1) {
          JOptionPane.showMessageDialog(this, e1.getMessage()
              + " - Only your inserted start project "
              + "date info won't be saved, don't worry about the rest.",
              "Hackystat - Error Message", JOptionPane.ERROR_MESSAGE);
          e1.printStackTrace();
        }
      }
      if (end != null && !end.equals(profileInEditingMode.profile.endDate) && end.trim() != "") {
        try {
          projObj.setEndTime(Tstamp.makeTimestamp(end));
        }
        catch (Exception e1) {
          JOptionPane.showMessageDialog(this, e1.getMessage()
              + " - Only your inserted end project "
              + "date info won't be saved, don't worry about the rest.",
              "Hackystat - Error Message", JOptionPane.ERROR_MESSAGE);
          e1.printStackTrace();
        }
      }
      if (modified != null && !modified.equals(profileInEditingMode.profile.modifiedDate)
          && modified.trim() != "") {
        try {
          projObj.setLastMod(Tstamp.makeTimestamp(modified));
        }
        catch (Exception e1) {
          JOptionPane.showMessageDialog(this, e1.getMessage()
              + " - Only your inserted last modification "
              + "date info won't be saved, don't worry about the rest.",
              "Hackystat - Error Message", JOptionPane.ERROR_MESSAGE);
          e1.printStackTrace();
        }
      }
      if (repAnon != null && !repAnon.equals(profileInEditingMode.profile.repositoryAnonymous)
          && repAnon.trim() != "") {
        projObj.addProperty(HackystatConstants.REPOSITORY_ANON_ROOT, repAnon);
      }
      if (!rep.equals(profileInEditingMode.profile.repository) && rep.trim() != "") {
        projObj.addProperty(HackystatConstants.REPOSITORY_LOCATION, rep);
      }
      if (!repWeb.equals(profileInEditingMode.profile.repositoryWebBrowserInterface)
          && repWeb.trim() != "") {
        projObj.addProperty(HackystatConstants.REPOSITORY_WEB_INTERFACE, repWeb);
      }
      if (tags != null) {
        projObj.addProperty(HackystatConstants.PROJECT_TAGS, tags);
      }
      if (tools != null) {
        projObj.addProperty(HackystatConstants.PROJECT_TOOLS, tools);
      }
      if (devPhases != null) {
        projObj.addProperty(HackystatConstants.PROJECT_PHASES, devPhases);
      }
      if (wikis != null) {
        projObj.addProperty(HackystatConstants.PROJECT_WIKI, wikis);
      }
      if (progrlangs != null) {
        projObj.addProperty(HackystatConstants.LANGUAGE, progrlangs);
      }
      if (osystems != null) {
        projObj.addProperty(HackystatConstants.OPERATING_SYSTEM, osystems);
      }
      if (bugdbs != null) {
        projObj.addProperty(HackystatConstants.PROJECT_BUG_DB, bugdbs);
      }
      if (mirrors != null) {
        projObj.addProperty(HackystatConstants.PROJECT_DOWLOAD_MIRRORS, mirrors);
      }
      if (!description.equals(profileInEditingMode.profile.description)) {
        projObj.setDescription(description);
      }
      projObj.setOwner(owner);
      projObj.setName(projname);
      try {
        if (projObj.getStartTime() == null) {
          projObj.setStartTime(Tstamp.makeTimestamp(profileInEditingMode.profile.startDate));
        }
        if (projObj.getEndTime() == null) {
          projObj.setEndTime(Tstamp.makeTimestamp(profileInEditingMode.profile.endDate));
        }
        if (projObj.getLastMod() == null) {
          projObj.setStartTime(Tstamp.makeTimestamp(profileInEditingMode.profile.modifiedDate));
        }
      }
      catch (Exception e3) {
        JOptionPane.showMessageDialog(this, "The system has failed to store your new entered data "
            + "due to start/end or last modification date missing.", "Hackystat - Message",
            JOptionPane.ERROR_MESSAGE);
        return;
      }
      try {
        mainframe.getLiSeDClient().addProjectData(projObj);
        JOptionPane.showMessageDialog(this, "Your new entered data have been saved.",
            "Hackystat - Message", JOptionPane.PLAIN_MESSAGE);
      }
      catch (LinkedServiceDataClientException e2) {
        JOptionPane.showMessageDialog(this, e2.getMessage(), "Hackystat - Error Message",
            JOptionPane.ERROR_MESSAGE);
        e2.printStackTrace();
        refreshProfiles();
      }
      disableAllJTextFields(profileInEditingMode);
      disableAllJTextAreas(profileInEditingMode);
      profileInEditingMode = null;
      refresh();

    }
    else if (source.equals(refreshButton)) {
      if (mainframe.isLogged()) {
        mainframe.getLiSeDClient().clearLocalCache();
        JOptionPane.showMessageDialog(this, "Local cache for the logged user has been cleared.",
            "Hackystat - Message", JOptionPane.PLAIN_MESSAGE);
        resetPanel();
      }
    }
    else if (source.equals(searchButton)) {
      new ProjectSearchWizard(mainframe);
    }
    else if (source.equals(addMembersRoleButton)) {
      String text = membersRoleValueText.getText() + " - " + rolesCombo.getSelectedItem();

      if (text != null && !text.trim().equals("")) {
        JList jlist = profileInEditingMode.membersRoleJList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (source.equals(removeMembersRoleButton)) {
      JList jlist = profileInEditingMode.membersRoleJList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (source.equals(addTagsButton)) {
      String text = tagsValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = profileInEditingMode.tagsJList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (source.equals(removeTagsButton)) {
      JList jlist = profileInEditingMode.tagsJList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (source.equals(addToolsButton)) {
      String text = toolsValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = profileInEditingMode.toolsJList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (source.equals(removeToolsButton)) {
      JList jlist = profileInEditingMode.toolsJList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
    else if (source.equals(addDevPhaseButton)) {
      String text = devPhaseValueText.getText();
      if (text != null && !text.trim().equals("")) {
        JList jlist = profileInEditingMode.devPhasesJList;
        DefaultListModel model = (DefaultListModel) jlist.getModel();
        model.addElement(text);
        jlist.repaint();
      }
    }
    else if (source.equals(removeDevPhaseButton)) {
      JList jlist = profileInEditingMode.devPhasesJList;
      int index = jlist.getSelectedIndex();
      if (index != -1) {
        ((DefaultListModel) jlist.getModel()).remove(index);
      }
      jlist.repaint();
    }
  }

  private String getNewElems(String str, LinkedList<String> listOrig, String splitElem) {
    String[] split = str.split(splitElem);
    boolean maybeequals = false;
    if (listOrig.size() == split.length) {
      maybeequals = true;
    }
    String ret = "";
    for (int i = 0; i < split.length; i++) {
      if (maybeequals) {
        if (!listOrig.contains(split[i])) {
          maybeequals = false;
        }
      }
      ret += split[i] + HackystatConstants.SEPARATOR1_ID;
    }
    if (maybeequals) {
      return null;
    }
    return ret;
  }

  private String getNewElems(JList jlist, LinkedList<String> listOrig) {
    String ret = "";
    DefaultListModel model = (DefaultListModel) jlist.getModel();
    boolean maybeequals = false;
    if (model.getSize() != listOrig.size()) {
      maybeequals = true;
    }
    for (int i = 0; i < model.getSize(); i++) {
      if (maybeequals) {
        if (!listOrig.contains(model.get(i))) {
          maybeequals = false;
        }
      }
      ret += model.get(i) + HackystatConstants.SEPARATOR1_ID;
    }
    if (maybeequals) {
      ret = null;
    }
    return ret;
  }

  public void refresh() {
    this.removeAll();
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBackground(Color.WHITE);
    if (mainframe.isLogged()) {
      clearCacheButton = new JButton("Clear cache", LinkedServiceDataUI.clearIcon);
      searchButton = new JButton("Search", LinkedServiceDataUI.searchIcon);
      refreshButton = new JButton("Refresh", LinkedServiceDataUI.refreshIcon);
      triplifyAllButton = new JButton("Triplify All", LinkedServiceDataUI.triplifyIcon);
      panel.add(mainframe.getHeader(this, searchButton, refreshButton, triplifyAllButton,
          clearCacheButton, "Projects"));
    }

    JPanel subpanel = null;
    for (ProjectProfileUIComponent profileComponent : profilesList) {
      subpanel = new JPanel();
      subpanel.setLayout(new BoxLayout(subpanel, BoxLayout.Y_AXIS));
      subpanel.setBackground(Color.WHITE);
      subpanel.add(fillInUserProfileData1(profileComponent));
      subpanel.add(getActionsOnProfile(profileComponent.profile.owner
          + HackystatConstants.SEPARATOR1_ID + profileComponent.profile.name));
      subpanel.setBorder(BorderFactory.createLineBorder(Color.blue));
      panel.add(subpanel);
    }

    panel.setBackground(Color.white);
    JScrollPane listScrollPane = new JScrollPane(panel);
    listScrollPane = mainframe.initSubPanelScrollPane(listScrollPane);
    this.add(listScrollPane);
    this.validate();
  }

  private JPanel getActionsOnProfile(String id) {
    JPanel horiz = new JPanel();
    horiz.setLayout(new BoxLayout(horiz, BoxLayout.X_AXIS));
    horiz.add(Box.createHorizontalStrut(this.getSize().width / 2));
    horiz.setBackground(Color.white);
    actionLabel = new JLabel();
    actionLabel = mainframe.initLabel(actionLabel, "Actions:");
    horiz.add(actionLabel);
    horiz.add(Box.createHorizontalStrut(5));

    if (profileInEditingMode != null
        && (profileInEditingMode.profile.owner + HackystatConstants.SEPARATOR1_ID + profileInEditingMode.profile.name)
            .equals(id)) {
      saveButton = new JButton("Save");
      saveButton = mainframe.initButton(saveButton, this, mainframe.buttonDimension,
          "Save changes.");
      saveButton.setActionCommand(SAVEPREFIX + id);
      horiz.add(saveButton);
    }
    else {
      editButton = new JButton("Edit");
      editButton = mainframe.initButton(editButton, this, mainframe.buttonDimension,
          "Edit data about this project.");
      editButton.setActionCommand(EDITPREFIX + id);
      horiz.add(editButton);
    }
    horiz.add(Box.createHorizontalStrut(5));

    triplifyOneButton = new JButton("Triplify", LinkedServiceDataUI.triplifyIcon);
    triplifyOneButton = mainframe.initButton(triplifyOneButton, this, mainframe.buttonDimension,
        "Get RDF representation of this project");
    triplifyOneButton.setActionCommand(TRIPLIFYPREFIX + id);
    horiz.add(triplifyOneButton);
    horiz.add(Box.createHorizontalGlue());
    return horiz;
  }

  private String getTextAreaContentFromList(LinkedList<String> list) {
    String empty = "", ret = empty;
    for (String str : list) {
      if (!str.trim().equals(empty)) {
        ret += str + splitElem;
      }
    }
    return ret;
  }

  private LinkedList<JTextArea> makeJTextAreas(ProjectProfile profile) {
    LinkedList<JTextArea> textlist = new LinkedList<JTextArea>();
    wikisText = new JTextArea(getTextAreaContentFromList(profile.getWikis()));
    wikisText = mainframe.initTextArea(wikisText, false);
    textlist.add(wikisText);
    progrLangsText = new JTextArea(getTextAreaContentFromList(profile.getProgrLangs()));
    progrLangsText = mainframe.initTextArea(progrLangsText, false);
    textlist.add(progrLangsText);
    mirrorsText = new JTextArea(getTextAreaContentFromList(profile.getMirrors()));
    mirrorsText = mainframe.initTextArea(mirrorsText, false);
    textlist.add(mirrorsText);
    bugDbText = new JTextArea(getTextAreaContentFromList(profile.getBugDBs()));
    bugDbText = mainframe.initTextArea(bugDbText, false);
    textlist.add(bugDbText);
    osText = new JTextArea(getTextAreaContentFromList(profile.getOperatingSystems()));
    osText = mainframe.initTextArea(osText, false);
    textlist.add(osText);
    descriptionText = new JTextArea(profile.description);
    descriptionText = mainframe.initTextArea(descriptionText, false);
    textlist.add(descriptionText);
    return textlist;
  }

  private LinkedList<JTextField> makeJTextFields(ProjectProfile profile) {
    LinkedList<JTextField> textlist = new LinkedList<JTextField>();
    visibilityText = new JTextField(1);
    visibilityText = mainframe.initTextField(visibilityText, profile.visibility, false);
    textlist.add(visibilityText);
    projNameText = new JTextField(5);
    projNameText = mainframe.initTextField(projNameText, profile.name, false);
    textlist.add(projNameText);
    ownerText = new JTextField(10);
    ownerText = mainframe.initTextField(ownerText, profile.owner, false);
    textlist.add(ownerText);
    startDateText = new JTextField(10);
    // String tooltip = "Use the date format 'yyyy-M-d' please";
    startDateText = mainframe.initTextField(startDateText, profile.startDate, false);
    textlist.add(startDateText);
    modifiedDateText = new JTextField(10);
    modifiedDateText = mainframe.initTextField(modifiedDateText, profile.modifiedDate, false);
    textlist.add(modifiedDateText);
    endDateText = new JTextField(10);
    endDateText = mainframe.initTextField(endDateText, profile.endDate, false);
    textlist.add(endDateText);
    repAnonText = new JTextField(10);
    repAnonText = mainframe.initTextField(repAnonText, profile.repositoryAnonymous, false);
    textlist.add(repAnonText);
    repText = new JTextField(10);
    repText = mainframe.initTextField(repText, profile.repository, false);
    textlist.add(repText);
    repWebInterfaceText = new JTextField(10);
    repWebInterfaceText = mainframe.initTextField(repWebInterfaceText,
        profile.repositoryWebBrowserInterface, false);
    textlist.add(repWebInterfaceText);

    return textlist;
  }

  /**
   * Monitor a correct displaying of this tab panel while the user is browsing between tabs. If he
   * is logged then the list of profiles for this panel is already updated and then it's not refresh
   * now.
   */
  public void prepareDisplaying() {
    if (!mainframe.isLogged()) {
      profilesList = new LinkedList<ProjectProfileUIComponent>();
    }
    else if (profilesList == null || profilesList.isEmpty()) {
      refreshProfiles();
    }
    refresh();
  }

  /**
   * Forces the resetting of the whole panel and re-fills it only if the current user is logged.
   * This is used after changes to the authentication state.
   */
  public void resetPanel() {
    this.profilesList = new LinkedList<ProjectProfileUIComponent>();
    if (mainframe.isLogged()) {
      refreshProfiles();
    }
    refresh();
  }

  private JList createJListFromList(LinkedList<String> list) {
    DefaultListModel model = new DefaultListModel();
    for (String dup : list) {
      model.addElement(dup);
    }
    JList jlist = new JList(model);
    jlist = mainframe.initJList(jlist);
    return jlist;
  }

  private JList createJListFromTwoElemList(LinkedList<String[]> list) {
    DefaultListModel model = new DefaultListModel();
    for (String[] dup : list) {
      model.addElement(dup[0] + " - " + dup[1]);
    }
    JList jlist = new JList(model);
    jlist = mainframe.initJList(jlist);
    return jlist;
  }

  private JList createJListFromMap(HashMap<String, String> list) {
    DefaultListModel model = new DefaultListModel();
    for (String dup : list.keySet()) {
      model.addElement(dup + " - " + list.get(dup));
    }
    JList jlist = new JList(model);
    jlist = mainframe.initJList(jlist);
    return jlist;
  }

  private JPanel fillInUserProfileData1(ProjectProfileUIComponent profileComponent) {
    JPanel horiz = new JPanel();
    horiz.setLayout(new BoxLayout(horiz, BoxLayout.X_AXIS));
    horiz.setBackground(Color.white);
    JPanel vertic = null;
    initLabelHeaders1();

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    vertic.add(visibilityLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(profileComponent.textFieldsList.get(0));
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(projNameLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(profileComponent.textFieldsList.get(1));
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(ownerLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(profileComponent.textFieldsList.get(2));
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(repAnonLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(profileComponent.textFieldsList.get(6));
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(repLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(profileComponent.textFieldsList.get(7));
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(repWebInterfaceLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(profileComponent.textFieldsList.get(8));
    horiz.add(vertic);

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    vertic.add(startDateLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(profileComponent.textFieldsList.get(3));
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(wikisLabel);
    vertic.add(Box.createVerticalStrut(1));
    JScrollPane listScrollPane = new JScrollPane(profileComponent.textAreasList.get(0));
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(progrLangsLabel);
    vertic.add(Box.createVerticalStrut(1));
    listScrollPane = new JScrollPane(profileComponent.textAreasList.get(1));
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(mirrorsLabel);
    vertic.add(Box.createVerticalStrut(1));
    listScrollPane = new JScrollPane(profileComponent.textAreasList.get(2));
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    horiz.add(vertic);

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    vertic.add(modifiedDateLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(profileComponent.textFieldsList.get(4));
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(bugDbLabel);
    vertic.add(Box.createVerticalStrut(1));
    listScrollPane = new JScrollPane(profileComponent.textAreasList.get(3));
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(osLabel);
    vertic.add(Box.createVerticalStrut(1));
    listScrollPane = new JScrollPane(profileComponent.textAreasList.get(4));
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(descriptionLabel);
    vertic.add(Box.createVerticalStrut(1));
    listScrollPane = new JScrollPane(profileComponent.textAreasList.get(5));
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    horiz.add(vertic);

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    vertic.add(endDateLabel);
    vertic.add(Box.createVerticalStrut(1));
    vertic.add(profileComponent.textFieldsList.get(5));
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(sameAsLabel);
    vertic.add(Box.createVerticalStrut(1));
    listScrollPane = new JScrollPane(profileComponent.sameAsJList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(seeAlsoLabel);
    vertic.add(Box.createVerticalStrut(1));
    listScrollPane = new JScrollPane(profileComponent.seeAlsoJList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    vertic.add(Box.createVerticalStrut(3));
    vertic.add(skillsLabel);
    vertic.add(Box.createVerticalStrut(1));
    listScrollPane = new JScrollPane(profileComponent.skillsJList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    vertic.add(listScrollPane);
    horiz.add(vertic);

    vertic = new JPanel();
    vertic.setLayout(new BoxLayout(vertic, BoxLayout.Y_AXIS));
    vertic.setBackground(Color.white);
    listScrollPane = new JScrollPane(profileComponent.membersRoleJList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (profileInEditingMode != null && profileInEditingMode.equals(profileComponent)) {
      if (addMembersRoleButton == null) {
        addMembersRoleButton = new JButton("Add >>");
        addMembersRoleButton = mainframe.initButton(addMembersRoleButton, this,
            mainframe.buttonDimension, "Add the inserted members/role " + "to the list");
      }
      if (removeMembersRoleButton == null) {
        removeMembersRoleButton = new JButton("Remove <<");
        removeMembersRoleButton = mainframe.initButton(removeMembersRoleButton, this,
            mainframe.buttonDimension, "Remove the inserted members/role " + "to the list");
      }
      membersRoleValueText = new JTextField(10);
      membersRoleValueText = mainframe.initTextField(membersRoleValueText, "", true);
      rolesComboLabel = new JLabel();
      rolesComboLabel = mainframe.initLabel(rolesComboLabel, "Roles:");
      rolesCombo = new JComboBox(HackystatConstants.ROLES_LIST);
      rolesCombo = mainframe.initComboBox(rolesCombo, this);
      vertic.add(mainframe.addJListFillingComponent(membersRoleValueLabel, membersRoleValueText,
          addMembersRoleButton, removeMembersRoleButton, membersRoleListLabel, listScrollPane,
          null, rolesComboLabel, rolesCombo));
    }
    else {
      vertic.add(membersRoleListLabel);
      vertic.add(Box.createVerticalStrut(1));
      vertic.add(listScrollPane);
    }
    vertic.add(Box.createVerticalStrut(3));
    listScrollPane = new JScrollPane(profileComponent.devPhasesJList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (profileInEditingMode != null && profileInEditingMode.equals(profileComponent)) {
      if (addDevPhaseButton == null) {
        addDevPhaseButton = new JButton("Add >>");
        addDevPhaseButton = mainframe.initButton(addDevPhaseButton, this,
            mainframe.buttonDimension, "Add the inserted development phase " + "to the list");
      }
      if (removeDevPhaseButton == null) {
        removeDevPhaseButton = new JButton("Remove <<");
        removeDevPhaseButton = mainframe.initButton(removeDevPhaseButton, this,
            mainframe.buttonDimension, "Remove the inserted development phase " + "to the "
                + "list");
      }
      devPhaseValueText = new JTextField(10);
      devPhaseValueText = mainframe.initTextField(devPhaseValueText, "", true);
      vertic.add(mainframe.addJListFillingComponent(devPhaseValueLabel, devPhaseValueText,
          addDevPhaseButton, removeDevPhaseButton, devPhaseLabel, listScrollPane, null));
    }
    else {
      vertic.add(devPhaseLabel);
      vertic.add(Box.createVerticalStrut(1));
      vertic.add(listScrollPane);
    }
    listScrollPane = new JScrollPane(profileComponent.tagsJList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (profileInEditingMode != null && profileInEditingMode.equals(profileComponent)) {
      if (addTagsButton == null) {
        addTagsButton = new JButton("Add >>");
        addTagsButton = mainframe.initButton(addTagsButton, this, mainframe.buttonDimension,
            "Add the inserted tag to the " + "list");
      }
      if (removeTagsButton == null) {
        removeTagsButton = new JButton("Remove <<");
        removeTagsButton = mainframe.initButton(removeTagsButton, this, mainframe.buttonDimension,
            "Remove the inserted tag " + "to the " + "list");
      }
      tagsValueText = new JTextField(10);
      tagsValueText = mainframe.initTextField(tagsValueText, "", true);
      vertic.add(mainframe.addJListFillingComponent(tagsValueLabel, tagsValueText, addTagsButton,
          removeTagsButton, tagsLabel, listScrollPane, null));
    }
    else {
      vertic.add(tagsLabel);
      vertic.add(Box.createVerticalStrut(1));
      vertic.add(listScrollPane);
    }
    vertic.add(Box.createVerticalStrut(3));
    listScrollPane = new JScrollPane(profileComponent.toolsJList);
    listScrollPane = mainframe.initJListScrollPane(listScrollPane);
    if (profileInEditingMode != null && profileInEditingMode.equals(profileComponent)) {
      if (addToolsButton == null) {
        addToolsButton = new JButton("Add >>");
        addToolsButton = mainframe.initButton(addToolsButton, this, mainframe.buttonDimension,
            "Add the inserted tool to the " + "list");
      }
      if (removeToolsButton == null) {
        removeToolsButton = new JButton("Remove <<");
        removeToolsButton = mainframe.initButton(removeToolsButton, this,
            mainframe.buttonDimension, "Remove the inserted tool " + "to the " + "list");
      }
      toolsValueText = new JTextField(10);
      toolsValueText = mainframe.initTextField(toolsValueText, "", true);
      vertic.add(mainframe.addJListFillingComponent(toolsValueLabel, toolsValueText,
          addToolsButton, removeToolsButton, toolsLabel, listScrollPane, null));
    }
    else {
      vertic.add(toolsLabel);
      vertic.add(Box.createVerticalStrut(1));
      vertic.add(listScrollPane);
    }
    horiz.add(vertic);

    return horiz;
  }

  private void initLabelHeaders1() {
    visibilityLabel = new JLabel();
    visibilityLabel = mainframe.initLabel(visibilityLabel, "Visibility:");

    projNameLabel = new JLabel();
    projNameLabel = mainframe.initLabel(projNameLabel, "Project Name:");

    ownerLabel = new JLabel();
    ownerLabel = mainframe.initLabel(ownerLabel, "Owner:");

    descriptionLabel = new JLabel();
    descriptionLabel = mainframe.initLabel(descriptionLabel, "Description:");

    mirrorsLabel = new JLabel();
    mirrorsLabel = mainframe.initLabel(mirrorsLabel, "Mirrors:");

    progrLangsLabel = new JLabel();
    progrLangsLabel = mainframe.initLabel(progrLangsLabel, "Programming Languages:");

    wikisLabel = new JLabel();
    wikisLabel = mainframe.initLabel(wikisLabel, "Wikis:");

    repAnonLabel = new JLabel();
    repAnonLabel = mainframe.initLabel(repAnonLabel, "Anonymous repository:");

    repLabel = new JLabel();
    repLabel = mainframe.initLabel(repLabel, "Repository:");

    repWebInterfaceLabel = new JLabel();
    repWebInterfaceLabel = mainframe.initLabel(repWebInterfaceLabel, "Repository Web interface:");

    osLabel = new JLabel();
    osLabel = mainframe.initLabel(osLabel, "Operating systems:");

    bugDbLabel = new JLabel();
    bugDbLabel = mainframe.initLabel(bugDbLabel, "Bug Databases:");

    rolesComboLabel = new JLabel();
    rolesComboLabel = mainframe.initLabel(rolesComboLabel, "Role:");

    startDateLabel = new JLabel();
    startDateLabel = mainframe.initLabel(startDateLabel, "Start date:");

    modifiedDateLabel = new JLabel();
    modifiedDateLabel = mainframe.initLabel(modifiedDateLabel, "Last modification date:");

    endDateLabel = new JLabel();
    endDateLabel = mainframe.initLabel(endDateLabel, "End date:");

    seeAlsoLabel = new JLabel();
    seeAlsoLabel = mainframe.initLabel(seeAlsoLabel, "See also:");

    sameAsLabel = new JLabel();
    sameAsLabel = mainframe.initLabel(sameAsLabel, "Same as:");

    skillsLabel = new JLabel();
    skillsLabel = mainframe.initLabel(skillsLabel, "Quality measures:");

    membersRoleListLabel = new JLabel();
    membersRoleListLabel = mainframe.initLabel(membersRoleListLabel, "Member/Role list:");

    membersRoleValueLabel = new JLabel();
    membersRoleValueLabel = mainframe.initLabel(membersRoleValueLabel, "Member's email:");

    tagsLabel = new JLabel();
    tagsLabel = mainframe.initLabel(tagsLabel, "Tags:");

    tagsValueLabel = new JLabel();
    tagsValueLabel = mainframe.initLabel(tagsValueLabel, "Tag value:");

    toolsLabel = new JLabel();
    toolsLabel = mainframe.initLabel(toolsLabel, "Tools:");

    toolsValueLabel = new JLabel();
    toolsValueLabel = mainframe.initLabel(toolsValueLabel, "Tool name:");

    devPhaseLabel = new JLabel();
    devPhaseLabel = mainframe.initLabel(devPhaseLabel, "Development Phase:");

    devPhaseValueLabel = new JLabel();
    devPhaseValueLabel = mainframe.initLabel(devPhaseValueLabel, "Name:");
  }

  private void displayWaitingDialog() {
    JProgressBar pb = new JProgressBar(0, 100);
    pb.setPreferredSize(new Dimension(175, 20));
    pb.setString("wait");
    pb.setIndeterminate(true);
    pb.setStringPainted(true);
    pb.setValue(0);
    JLabel label = new JLabel("The list of projects is being downloaded "
        + "from LiSeD service. Please wait...");
    JPanel center_panel = new JPanel();
    center_panel.setLayout(new BoxLayout(center_panel, BoxLayout.Y_AXIS));
    center_panel.add(label);
    center_panel.add(Box.createVerticalStrut(2));
    center_panel.add(pb);
    dialog = new JDialog(mainframe, "Please wait...");

    dialog.setLocationRelativeTo(null); // center on screen
    dialog.setLocation(550, 25); // position by coordinates
    dialog.toFront(); // raise above other java windows

    dialog.getContentPane().add(center_panel, BorderLayout.CENTER);
    dialog.pack();
    dialog.setVisible(true);
    this.setEnabled(false);
    mainframe.setEnabled(false);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent we) {
        setEnabled(true);
        mainframe.setEnabled(true);
        dialog.dispose();
        dialog = null;
      }
    });
    // dialog.setBackground(Color.white);
  }

  public void disposeDialog() {
    this.setEnabled(true);
    mainframe.setEnabled(true);
    if (dialog != null) {
      dialog.dispose();
    }
  }

  public void displayPasswordRequiredDialog(String email) {
    JPanel center_panel = new JPanel();
    center_panel.setLayout(new BoxLayout(center_panel, BoxLayout.Y_AXIS));
    JLabel label = new JLabel("Insert the selected user's password:");
    center_panel.add(label);
    center_panel.add(Box.createVerticalStrut(2));
    passwordText = new JPasswordField();
    center_panel.add(passwordText);
    center_panel.add(Box.createVerticalStrut(5));
    okButton = new JButton();
    okButton.setMnemonic(KeyEvent.VK_S);
    okButton.setFont(new Font("Dialog", java.awt.Font.BOLD, mainframe.buttonFontSize));
    okButton.setText("OK");
    okButton.addActionListener(this);
    okButton.setSize(mainframe.triplifyButtonDimension);
    okButton.setPreferredSize(mainframe.triplifyButtonDimension);
    okButton.setMaximumSize(mainframe.triplifyButtonDimension);
    okButton.setMinimumSize(mainframe.triplifyButtonDimension);
    okButton.setActionCommand(OKPREFIX + email);
    center_panel.add(okButton);

    dialog = new JDialog(mainframe, "Insert Password");

    dialog.setLocationRelativeTo(null); // center on screen
    // dialog.setLocation(550,25); // position by coordinates
    dialog.toFront(); // raise above other java windows

    dialog.getContentPane().add(center_panel, BorderLayout.CENTER);
    dialog.pack();
    dialog.setVisible(true);
    this.setEnabled(false);
    mainframe.setEnabled(false);
    dialog.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent we) {
        setEnabled(true);
        mainframe.setEnabled(true);
        dialog.dispose();
        dialog = null;
      }
    });
    dialog.setBackground(Color.white);
  }

  public void displayRDFContentDialog(String serializedModel) {
    JTextArea area = new JTextArea(serializedModel);
    area.setColumns(mainframe.jdialogTextAreaNumCols);
    area.setRows(mainframe.jdialogTextAreaNumRows);
    area.setEditable(false);
    JScrollPane listScrollPane = new JScrollPane(area);
    listScrollPane.setPreferredSize(mainframe.jdialogAreaDimension);
    listScrollPane.setMaximumSize(mainframe.jdialogAreaDimension);
    listScrollPane.setMinimumSize(mainframe.jdialogAreaDimension);
    JLabel label = new JLabel("RDF serialization using the language " + this.language);
    JPanel center_panel = new JPanel();
    center_panel.setLayout(new BoxLayout(center_panel, BoxLayout.Y_AXIS));
    center_panel.add(label);
    center_panel.add(Box.createVerticalStrut(5));
    center_panel.add(listScrollPane);
    JDialog dialog1 = new JDialog(mainframe, "RDF User Profiles");

    dialog1.setLocationRelativeTo(null); // center on screen
    dialog1.setLocation(550, 25); // position by coordinates
    dialog1.toFront(); // raise above other java windows

    dialog1.getContentPane().add(center_panel, BorderLayout.CENTER);
    dialog1.pack();
    dialog1.setVisible(true);

    dialog1.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  }

  @Override
  public void itemStateChanged(ItemEvent e) {
    // TODO Auto-generated method stub

  }
}
